package com.cs.study.homework._0207;

import java.util.Scanner;

public class Demo7 {
    public static void main(String[] args) {
        Item phone = new Item();
        phone.category = "手机类";
        phone.name = "Samsung Galaxy S21";
        phone.price = 8000;
        phone.printMenu();

        Item furniture = new Item();
        furniture.category = "家具类";
        furniture.name = "海尔冰箱";
        furniture.price = 3000;
        furniture.printMenu();

        Item dailyNecessities = new Item();
        dailyNecessities.category = "日用品类";
        dailyNecessities.name = "海飞丝洗发水";
        dailyNecessities.price = 30;
        dailyNecessities.printMenu();

        System.out.println(phone.buy(8000));
        System.out.println(furniture.buy(3000));
        System.out.println(dailyNecessities.buy(30));




    }
}

class Item {
     String name;
     double price;
     String category;

    public void printMenu(){
        System.out.println(category + "的" + name + "卖" + price + "元");
    }
    public double buy(double price) {
        System.out.println("输入购买使用的金钱：");
        Scanner sc = new Scanner(System.in);
        double money = sc.nextDouble();
        if (money >= price) {
            double change = money - price;
            System.out.println(category + "的" + name + "卖掉了");
            return change;
        }else {
            System.out.println("金钱不足，购买失败");
            return -1;
        }
    }
}
